# 需求 从站长素材网站下载美女图片
import urllib.request
import urllib.parse
import lxml.etree
import uuid

url = "https://sc.chinaz.com/tupian/ribenmeinv.html"  # 第一页
url = "https://sc.chinaz.com/tupian/ribenmeinv_2.html"  # 第二页

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0",
}
for i in range(1, 6):
    if i == 1:
        part = ""
    else:
        part = f"_{i}"
    url = f"https://sc.chinaz.com/tupian/ribenmeinv{part}.html"
    request = urllib.request.Request(url, headers=headers)

    response = urllib.request.urlopen(request)

    content = response.read().decode("utf8")
    etree_html = lxml.etree.HTML(content)  # type:lxml.etree._Element
    img_urls = etree_html.xpath("//div[@class='tupian-list com-img-txt-list']/div[@class='item']/img/@data-original")
    for img_url in img_urls:
        name=img_url[img_url.rindex("/")+1:]
        urllib.request.urlretrieve("https:"+img_url,name)


